//
//  Friend.m
//  YSSmartHome
//
//  Created by yanghao on 18/04/2017.
//  Copyright © 2017 yahaong. All rights reserved.
//

#import "Friend.h"

@implementation Friend

- (instancetype)initWithMobile:(NSString*)mobile apsn: (XAITYPEAPSN) apsn{
    XAITYPELUID luid = [XAI mobileToLuid:mobile];
    self = [super initWithApsn:apsn Luid:luid];
    if (self) {
        _mobile = mobile;
    }
    return self;
}

- (void)reciveStatus:(uint32_t)gatewayApsn
          deviceLuid:(uint64_t )deviceLuid
         triggerApsn:( uint32_t)triggerApsn
         triggerLuid:(uint64_t)triggerLuid
           timestamp:(uint32_t)timestamp
            statusID:(uint8_t)statusID
                data:(XAITLV*__nonnull)data
           isHistory:(BOOL)isHistory {
    if (data == nil) {
        return;
    }
    switch (statusID) {
            
        case 0xff:
        {
            if (isHistory) {
                
            } else {
                self.name = [[NSString alloc]initWithBytes:[data getPayloadbyte] length:data.payloadlen encoding:NSUTF8StringEncoding];
                [kDataManager friendRefreshCallBackWithType:FriendCallbackTypeName];
            }
        }
            break;
        case 0xfe:
        {
            if (isHistory) {
                
            } else {
                uint8_t status = 0;
                memcpy(&status, [data getPayloadbyte], sizeof(uint8_t));
                self.devStatus = status;
                [kDataManager friendRefreshCallBackWithType:FriendCallbackTypeConnectStatus];
            }
        }
            break;
        case 0xfd:
        {
            if (isHistory) {
                
            } else {
                uint8_t status = 0;
                memcpy(&status, [data getPayloadbyte], sizeof(uint8_t));
                self.devStatus = status;
                [kDataManager friendRefreshCallBackWithType:FriendCallbackTypePower];
            }
        }
            break;
        default:
            break;
    }
}

@end
